export default {
    // 转化时长
    toDduration: function (duration) {
        let result = parseInt(duration);
        let h =
            Math.floor(result / 3600) < 10 ?
            "0" + Math.floor(result / 3600) :
            Math.floor(result / 3600);
        let m =
            Math.floor((result / 60) % 60) < 10 ?
            "0" + Math.floor((result / 60) % 60) :
            Math.floor((result / 60) % 60);
        let s =
            Math.floor(result % 60) < 10 ?
            "0" + Math.floor(result % 60) :
            Math.floor(result % 60);

        let res = "";
        if (h !== "00") {
            res += `${h}时`;
        }
        if (m !== "00") {
            res += `${m}分`;
        }
        res += `${s}秒`;

        return res;
    },
    // 格式化时间（yyyy-MM-dd HH:mm:ss）
    formatTime: function (time) {
        var year = time.getFullYear();
        var month = this.padDateTime(time.getMonth() + 1);
        var day = this.padDateTime(time.getDate());
        var hours = this.padDateTime(time.getHours());
        var minutes = this.padDateTime(time.getMinutes());
        var seconds = this.padDateTime(time.getSeconds());
        return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    },
    // 转化日期时间
    padDateTime: function (value) {
        return value < 10 ? '0' + value : value;
    },

}